package cycle.retrieve;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import cycle.RentDescription;
import cycle.RentSolution;

import jcolibri.cbrcore.CBRCase;
import jcolibri.method.retrieve.RetrievalResult;

public class RetrieveResult {
	
	private Collection<RetrievalResult> eval;
	private Collection<CBRCase> selectedcases;
	private List<RetrievalResult> cases;
	private int k;
	
	public RetrieveResult(Collection<RetrievalResult> eval, Collection<CBRCase> selectedcases, int k) {
		
		cases = new ArrayList<RetrievalResult>();
		this.k = k;
		this.selectedcases = selectedcases;
		this.eval = eval;
		
		for(RetrievalResult rr: this.eval) {
			if(this.selectedcases.contains(rr.get_case())) {
				this.cases.add(rr);
			}
		}
		
	}
	
	public void printRetrievalResult() {
		for(int i=0;i<this.k;i++) {
			RentDescription desc = getCaseDescription(i);
			RentSolution sol = getCaseSolution(i);
			System.out.println("Retrieval Result: "+getSimilarity(i) + " ("+ getCase(i).getID() + ";"+desc.getBairro()+";"+desc.getRegiao()+
					";"+desc.getAreaPrivativa()+";"+desc.getVagasGaragem()+";"+desc.getQuartos()+";"+
					desc.getSuites()+") Solution: ("+sol.getAluguelMensal()+";"+sol.getNomeEdificio()+");");
			
		}
	}
	
	public CBRCase getCase(int i) {
		RetrievalResult rr = cases.get(i);
		CBRCase _case = rr.get_case();
		return _case;
	}
	
	public String getNomeEdificio(int _case) {
		RentSolution sol = getCaseSolution(_case);
		return sol.getNomeEdificio();
	}
	
	public double getAluguelMensal(int _case) {
		RentSolution sol = getCaseSolution(_case);
		return sol.getAluguelMensal();
	}
	
	public String getBairro(int _case) {
		RentDescription desc = getCaseDescription(_case);
		return desc.getBairro();
	}
	
	public String getRegiao(int _case) {
		RentDescription desc  = getCaseDescription(_case);
		return desc.getRegiao();
	}
	
	public double getAreaPrivativa(int _case) {
		RentDescription desc  = getCaseDescription(_case);
		return desc.getAreaPrivativa();
	}
	
	public int getVagasGaragem(int _case) {
		RentDescription desc  = getCaseDescription(_case);
		return desc.getVagasGaragem();
	}
	
	public int getQuartos(int _case) {
		RentDescription desc  = getCaseDescription(_case);
		return desc.getQuartos();
	}

	public int getSuites(int _case) {
		RentDescription desc  = getCaseDescription(_case);
		return desc.getSuites();
	}
	
	public RentDescription getCaseDescription(int _caseNumber) {
		CBRCase _case = getCase(_caseNumber);
		return (RentDescription) _case.getDescription();
	}
	
	public RentSolution getCaseSolution(int _caseNumber) {
		CBRCase _case = getCase(_caseNumber);
		return (RentSolution) _case.getSolution();
	}
	
	public double getSimilarity(int _case) {
		RetrievalResult rr = cases.get(_case);
		return rr.getEval();
	}
}